<template>
  <div class="equipmentDataManagement zy-content">
    <div class="search clear">
      <!-- <Tabs type="card" v-model="tagName" @on-click="handleChangeTab">
        <TabPane
          v-for="(item, index) in tagList"
          :key="index"
          :label="item.name"
          :name="item.id"
        >
        </TabPane>
      </Tabs>-->
      <!--查询条件-->
      <div class="search-box-layout">
        <Row :gutter="24">
          <Col span="4">
            <div>
              <p class="label">{{ $t("equipCheck.SerialNo") }}</p>
              <div class="ipt">
                <Input
                  type="text"
                  clearable
                  v-model="searchParams.deviceMId"
                  :placeholder="`${$t('common.inputInfo')}`"
                  class="inputBorder"
                  :maxlength="32"
                ></Input>
              </div>
            </div>
          </Col>

          <Col span="4">
            <div>
              <p class="label">{{ $t("equipCheck.EquipmentName") }}</p>
              <div class="ipt">
                <Input
                  type="text"
                  clearable
                  v-model="searchParams.deviceName"
                  :placeholder="`${$t('common.inputInfo')}`"
                  class="inputBorder"
                  :maxlength="32"
                ></Input>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("equipCheck.AssetNo") }}</p>
              <div class="ipt">
                <Input
                  clearable
                  type="text"
                  v-model="searchParams.assetCode"
                  :placeholder="`${$t('common.inputInfo')}`"
                  class="inputBorder"
                  :maxlength="32"
                ></Input>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("equipCheck.EquipmentNo") }}</p>
              <div class="ipt">
                <Input
                  clearable
                  type="text"
                  v-model="searchParams.deviceNo"
                  :placeholder="`${$t('common.inputInfo')}`"
                  class="inputBorder"
                  :maxlength="32"
                ></Input>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">数采编号</p>
              <div class="ipt">
                <Input
                  clearable
                  type="text"
                  v-model="searchParams.dataAcquisitionNo"
                  :placeholder="`${$t('common.inputInfo')}`"
                  class="inputBorder"
                  :maxlength="32"
                ></Input>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("设备等级") }}</p>
              <div class="ipt">
                <Select
                  v-model="searchParams.deviceGrade"
                  filterable
                  clearable
                  :placeholder="`${$t('common.selectInfo')}`"
                >
                  <Option
                    v-for="(item, index) of deviceList"
                    :value="item.value"
                    :key="index"
                    :label="item.label"
                  ></Option>
                </Select>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("equipCheck.Status") }}</p>
              <div class="ipt">
                <Select
                  v-model="searchParams.deviceState"
                  filterable
                  clearable
                  :placeholder="`${$t('common.selectInfo')}`"
                >
                  <Option
                    v-for="(item, index) of deviceStatusList"
                    :value="item.value"
                    :key="index"
                    :label="item.value"
                  ></Option>
                </Select>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">功能位置</p>
              <div class="ipt">
                <Cascader
                  clearable
                  :data="orgList"
                  v-model="searchParams.installPosition"
                  change-on-select
                  :placeholder="`${$t('common.selectInfo')}`"
                ></Cascader>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("规格型号") }}</p>
              <div class="ipt">
                <Input
                  clearable
                  type="text"
                  v-model="searchParams.deviceSpec"
                  :placeholder="`${$t('common.inputInfo')}`"
                  class="inputBorder"
                  :maxlength="32"
                ></Input>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("ledger.PBoxBinding") }}</p>
              <div class="ipt">
                <Select
                  v-model="searchParams.isBindBox"
                  filterable
                  clearable
                  :placeholder="`${$t('common.selectInfo')}`"
                >
                  <Option
                    v-for="(item, index) of boxs"
                    :value="item.value"
                    :key="index"
                    :label="item.label"
                  ></Option>
                </Select>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("ledger.FixedAssetsTransferDate") }}</p>
              <div class="ipt">
                <DatePicker
                  @on-change="
                    (val) => {
                      searchParams.toRegularDate = val;
                    }
                  "
                  type="date"
                  :placeholder="$t('common.selectInfo')"
                />
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("common.AssetClassfication") }}</p>
              <div class="ipt">
                <Select
                  v-model="searchParams.assetId"
                  filterable
                  clearable
                  :placeholder="$t('common.selectInfo')"
                >
                  <Option
                    v-for="(item, index) of assetsList"
                    :value="item.value"
                    :key="index"
                    :label="item.value"
                  ></Option>
                </Select>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label">{{ $t("设备类别") }}</p>
              <div class="ipt">
                <Select
                  v-model="searchParams.deviceCategory"
                  filterable
                  clearable
                  :placeholder="`${$t('common.selectInfo')}`"
                >
                  <Option
                    v-for="(item, index) of deviceTypeList"
                    :value="item.value"
                    :key="index"
                    :label="item.value"
                  />
                </Select>
              </div>
            </div>
          </Col>
          <Col span="4">
            <div>
              <p class="label hide-label">--</p>
              <div class="ipt">
                <Button
                  type="primary"
                  class="search-btn"
                  @click="changeNum()"
                  v-has="'dmsDeviceTzGetDeviceTzList'"
                  >{{ $t("common.Query") }}</Button
                >
                <Button
                  class="reset-btn"
                  @click="reset()"
                  v-has="'dmsDeviceTzGetDeviceTzList'"
                  >{{ $t("common.reset") }}</Button
                >
              </div>
            </div>
          </Col>
        </Row>
      </div>
      <!-- 功能列表 -->
      <div class="list-layout mt16">
        <div class="btns clear">
          <span class="title">{{ $t("common.listInformation") }}</span>

          <Button v-has="'batchEnable'" @click="changeStatus(true)">批量启用 </Button>
          <Button v-has="'batchUnable'" @click="changeStatus(false)">批量禁用 </Button>
          <!-- <Button @click="handleBatchImport(2)">{{ $t("批量更新") }}
          </Button>
          <Button @click="exportUpdateTemplate">
            {{ $t("批量更新模板") }}
          </Button>
          <Button @click="handleBatchImport(1)" v-if="checkBtnPermission.dmsDeviceTzImportUpdate">{{
            $t("preliminary.BatchUpload") }}
          </Button>
          <Button @click="handleBatchImport(0)" v-if="checkBtnPermission.dmsDeviceTzImport">{{ $t("maintenance.Import") }}
          </Button>-->
          <Button @click="updateInfo({})">{{ $t("common.New") }}</Button>
          <Button
            @click="exportTemplateClick"
            v-if="checkBtnPermission.dmsDeviceTzExportTz"
            >{{ $t("maintenance.Export") }}</Button
          >
          <!-- <Button @click="exportTemplate" v-if="checkBtnPermission.dmsDeviceTzTemplate">
            {{ $t("preliminary.DownloadTemplate") }}
          </Button>-->

          <!-- <Button @click="batchScore" v-has="'dmsDeviceTzBatchScore'">
            {{ $t('批量评分') }}
          </Button>-->

          <!-- <Button @click="handleMulDelete">{{
            $t("common.batchDelete")
          }}</Button>-->
          <!-- <Button v-has="'dmsDeviceTzGetBatchDevicePrint'" @click="printShowClick">{{ $t("选择打印") }}</Button>
          <Button @click="getTableColumns(columns)">{{
            handleContextMenuStatus ? $t("显示操作栏") : $t("隐藏操作栏")
          }}</Button>-->
        </div>
        <div class="tableContent">
          <Table
            class="resizable-table"
            border
            @on-column-width-resize="onColumnWidthResize"
            ref="selection"
            row-key="id"
            :columns="columns"
            :data="dataSource"
            @on-selection-change="handleSelectionChange"
          >
            <!-- <template slot-scope="{ row }" slot="isBindBox">
              {{ row.isBindBox == 1 ? $t("common.Yes") : $t("common.No") }}
            </template>-->
            <template slot-scope="{ row }" slot="action">
              <span
                class="operationBtn"
                @click="handleledgerDetail(row)"
                v-has="'dmsDeviceTzGetTzDetailByDeviceEq'"
              >
                <i class="iconfont zy-common-chakan"></i>
                {{ $t("common.Check") }}
              </span>
              <span
                class="operationBtn"
                @click="updateInfo(row)"
                v-if="
                  checkBtnPermission.dmsDeviceTzUpdateDevice &&
                  row.deviceStatus !== '3'
                "
              >
                <i class="iconfont zy-common-bianji"></i>
                {{ $t("common.Edit") }}
              </span>

              <Dropdown
                transfer-class-name="theme-dropdown"
                :transfer="true"
                placement="left-start"
                v-if="
                  checkBtnPermission.dmsDeviceTzScore ||
                  checkBtnPermission.dmsDeviceTzAddFiles ||
                  checkBtnPermission.dmsDeviceTzUpdateDeviceNo ||
                  checkBtnPermission.dmsDeviceTzGetDevicePrint ||
                  checkBtnPermission.dmsDeviceTzDeleteById
                "
              >
                <a href="javascript:void(0)">
                  <i class="iconfont zy-common-gengduo1"></i>
                  {{ $t("common.more") }}
                  <Icon type="arrow-down-b"></Icon>
                </a>
                <Dropdown-menu slot="list">
                  <Dropdown-item
                    v-if="checkBtnPermission.dmsDeviceTzScore"
                    @click.native="handleledgerScore(row)"
                  >
                    <span class="operationBtn">{{
                      $t("ledger.EquipmentScoring")
                    }}</span>
                  </Dropdown-item>

                  <Dropdown-item
                    v-if="checkBtnPermission.dmsDeviceTzAddFiles"
                    @click.native="handleManyFile(row)"
                  >
                    <span class="operationBtn">{{
                      $t("preliminary.Upload")
                    }}</span>
                  </Dropdown-item>

                  <Dropdown-item
                    v-if="checkBtnPermission.dmsDeviceTzUpdateDeviceNo"
                    @click.native="handleUpdateDeviceNo(row)"
                  >
                    <span class="operationBtn">{{
                      $t("maintenance.editEquipmentNo")
                    }}</span>
                  </Dropdown-item>
                  <Dropdown-item
                    v-if="checkBtnPermission.dmsDeviceTzGetDevicePrint"
                    @click.native="handlePrint(row)"
                  >
                    <span class="operationBtn">{{
                      $t("preliminary.PrintQRCode")
                    }}</span>
                  </Dropdown-item>

                  <Dropdown-item
                    v-if="checkBtnPermission.dmsDeviceTzDeleteById"
                    @click.native="handleDelete(row)"
                  >
                    <span class="operationBtn">{{ $t("common.Delete") }}</span>
                  </Dropdown-item>
                </Dropdown-menu>
              </Dropdown>
            </template>
          </Table>
        </div>
        <div class="pageWrap mt16">
          <pageLeftTitle :total="total" :selected="ids.length" />
          <Page
            :total="total"
            :page-size="pageSize"
            :page-size-opts="$variable.pageSizes"
            :current="pageNum"
            @on-change="changePageNum"
            @on-page-size-change="changePageSize"
            show-sizer
            show-total
          />
        </div>
      </div>
    </div>
    <!--打印-->
    <ledger-print-modal ref="ledgerPrintModal" />
    <!--批量导入-->
    <import-excel-modal
      :isUpdate="isUpdate"
      :importExcelStateF="importExcelState"
      v-if="importExcelState"
      @importExcelChange="importExcelChange"
    />
    <!--        <ledger-batch-print-modal ref="ledgerBatchPrintModal"-->
    <!--                                  @handleChangeVisible="handleChangeVisible"/>-->
    <Modal :mask-closable="false" v-model="writeVisible" title="修改设备编号">
      <Form
        class="formList"
        ref="deviceNoForm"
        :model="formItem"
        :label-width="120"
        :rules="validateWritefunction"
      >
        <FormItem label="设备编号：" prop="deviceNo">
          <Input maxlength="20" show-word-limit v-model="formItem.deviceNo" />
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="default" @click="writeVisible = false">
          {{ $t("common.Cancle") }}
        </Button>
        <Button type="primary" :loading="loading" @click="handleOk">
          {{ $t("maintenance.Confirmed") }}
        </Button>
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      width="700"
      v-model="uploadVisible"
      :title="`${$t('maintenance.BasicInformation')}`"
      :footer-hide="true"
      class="modal-wrap-layout uploadFile"
    >
      <Form class="formList" :label-width="100">
        <FormItem :label="`${$t('设备外观图片')}`">
          <!--                <FormItem label="选择文件：">-->
          <Upload
            :before-upload="selecthandleUpload3"
            :show-upload-list="true"
            type="drag"
            style="width: 110px"
          >
            <Button icon="ios-cloud-upload-outline" :loading="uploadLoading">
              {{ $t("ledger.uploadFiles") }}
            </Button>
          </Upload>
          <div style="min-height: 100px">
            <div
              class="file-list"
              v-show="item.path === 'DEVICE_PICTURE'"
              v-for="(item, index) in fileList"
              :key="index"
            >
              <Tag
                class="item-src"
                color="blue"
                closable
                type="border"
                @on-close="delFileList(item.id)"
                @clock="handlePreview(item)"
                >{{ item.fileName }}</Tag
              >
            </div>
          </div>
        </FormItem>
        <FormItem :label="`${$t('设备工程图纸')}`">
          <!--                <FormItem label="选择文件：">-->
          <Upload
            :before-upload="selecthandleUpload"
            :show-upload-list="true"
            type="drag"
            style="width: 110px"
          >
            <Button icon="ios-cloud-upload-outline" :loading="uploadLoading">
              {{ $t("ledger.uploadFiles") }}
            </Button>
          </Upload>
          <div style="min-height: 100px">
            <div
              class="file-list"
              v-show="item.path === 'EQUIPMENT_ENGINEERING_DRAWINGS'"
              v-for="(item, index) in fileList"
              :key="index"
            >
              <Tag
                class="item-src"
                color="blue"
                closable
                type="border"
                @on-close="delFileList(item.id)"
                @clock="handlePreview(item)"
                >{{ item.fileName }}</Tag
              >
            </div>
          </div>
        </FormItem>
        <FormItem :label="`${$t('设备出厂附件')}`">
          <!--                <FormItem label="选择文件：">-->
          <Upload
            :before-upload="selecthandleUpload1"
            :show-upload-list="true"
            type="drag"
            style="width: 110px"
          >
            <Button icon="ios-cloud-upload-outline" :loading="uploadLoading">
              {{ $t("ledger.uploadFiles") }}
            </Button>
          </Upload>
          <div style="min-height: 100px">
            <div
              class="file-list"
              v-show="item.path === 'EQUIPMENT_FACTORY_ACCESSORIES'"
              v-for="(item, index) in fileList"
              :key="index"
            >
              <Tag
                class="item-src"
                color="blue"
                closable
                type="border"
                @on-close="delFileList(item.id)"
                @clock="handlePreview(item)"
                >{{ item.fileName }}</Tag
              >
            </div>
          </div>
        </FormItem>
        <FormItem :label="`${$t('作业指导书')}`">
          <!--                <FormItem label="选择文件：">-->
          <Upload
            :before-upload="selecthandleUpload2"
            :show-upload-list="true"
            type="drag"
            style="width: 110px"
          >
            <Button icon="ios-cloud-upload-outline" :loading="uploadLoading">
              {{ $t("ledger.uploadFiles") }}
            </Button>
          </Upload>
          <div style="min-height: 100px">
            <div
              class="file-list"
              v-show="item.path === 'E_SOP'"
              v-for="(item, index) in fileList"
              :key="index"
            >
              <Tag
                class="item-src"
                color="blue"
                closable
                type="border"
                @on-close="delFileList(item.id)"
                @clock="handlePreview(item)"
                >{{ item.fileName }}</Tag
              >
            </div>
          </div>
        </FormItem>
      </Form>
    </Modal>
    <Modal
      :mask-closable="false"
      v-model="delelteVisible"
      :title="`${$t('maintenance.editEquipmentNo')}`"
    >
      <Row class="enableContent">
        <Col span="24" class="enableContentInner">
          <img width="95px" src="~images/event/del.png" alt />
        </Col>
        <Col span="24" class="enableTips">
          <span>{{ $t("common.sureDelete") }}</span>
        </Col>
      </Row>
      <div slot="footer">
        <Button type="default" @click="delelteVisible = false">
          {{ $t("common.Cancle") }}
        </Button>
        <Button type="primary" :loading="delLoading" @click="handleDeleteOk">{{
          $t("maintenance.Confirmed")
        }}</Button>
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      class="modal-title-layout"
      v-model="delFaultCodeShowF"
      :title="`${$t('maintenance.Deleteremind')}`"
    >
      <div class="icon red">
        <i class="iconfont zy-common-shanchu"></i>
      </div>
      <p class="title">
        <span>{{ $t("common.sureDelete") }}</span>
      </p>
      <div slot="footer">
        <Button type="default" @click="delFaultCodeShowF = false">
          {{ $t("common.Cancle") }}
        </Button>
        <Button type="primary" :loading="delDeviceLoading" @click="deleteOk">{{
          $t("maintenance.Confirmed")
        }}</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import { findOrgByToken } from "@/api/index.js";
import fileDownload from "js-file-download";
import moment from "moment";
import importExcelModal from "../../../components/importExcel.vue";
import recursion from "../../../util/recursion";
import ledgerPrintModal from "./modules/ledgerPrintModal";
// import LedgerBatchPrintModal from "./modules/ledgerBatchPrintModal";
// import {Icon} from 'iview'
import toggleTableOperation from "@/mixins/toggleTableOperation";
export default {
  name: "equipmentsLedgerPageList",
  mixins: [toggleTableOperation],
  components: {
    // LedgerBatchPrintModal,
    ledgerPrintModal,
    importExcelModal,
  },
  data() {
    return {
      col: [
        {
          label: "姓名",
          prop: "name",
          search: true,
          type: "select",
        },
        {
          label: "性别",
          prop: "sex",
          search: true,
          searchOrder: 1,
        },
      ],

      isUpdate: 0, //是否台账更新
      status: "",
      delId: "",
      delDeviceId: "", //台账删除
      uploadId: "",
      tagName: "",
      total: 0,
      pageNum: 1,
      pageSize: 10,
      delFaultCodeShowF: false, //删除模态框显示
      delDeviceLoading: false,
      uploadVisible: false,
      importExcelState: false,
      writeVisible: false,
      loading: false,
      uploadLoading: false,
      delLoading: false,
      delelteVisible: false,
      searchParams: {},
      checkBtnPermission: {},
      formItem: {
        deviceNo: "",
      },
      validateWritefunction: {
        deviceNo: [
          {
            required: true,
            message: this.$t("equipLedger.inputDeviceNo"),
            trigger: "change",
          },
        ],
      },
      pageSizeOption: [10, 20, 30],
      statusList: [
        { id: 0, name: this.$t("common.all") },
        { id: 2, name: this.$t("equipLedger.waitTest") },
        {
          id: 3,
          name: this.$t("equipLedger.testing"),
        },
        { id: 4, name: this.$t("equipLedger.tested") },
        { id: 5, name: this.$t("preliminary.Checking") },
        {
          id: 6,
          name: this.$t("fault.Accepted"),
        },
        { id: 7, name: this.$t("equipLedger.payed") },
      ],

      columns: [
        {
          type: "selection",
          minWidth: 60,
          align: "center",
        },
        {
          title: `${this.$t("equipCheck.Status")}`,
          key: "deviceState",
          align: "center",
          minWidth: 120,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("equipCheck.SerialNo")}`,
          key: "deviceMId",
          align: "center",
          minWidth: 160,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("equipCheck.AssetNo")}`,
          key: "assetCode",
          align: "center",
          minWidth: 180,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("equipCheck.EquipmentNo")}`,
          key: "deviceNo",
          align: "center",
          minWidth: 180,
          resizable: true,
          tooltip: true,
        },
        {
          title: "数采编号",
          key: "dataAcquisitionNo",
          align: "center",
          minWidth: 180,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("preliminary.EquipmentName")}`,
          key: "deviceName",
          align: "center",
          minWidth: 160,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("设备类别")}`,
          key: "deviceCategory",
          align: "center",
          minWidth: 180,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("设备等级")}`,
          key: "deviceGrade",
          align: "center",
          minWidth: 120,
          resizable: true,
          tooltip: true,
        },
        {
          title: "资产分类",
          key: "assetType",
          align: "center",
          minWidth: 100,
          resizable: true,
        },
        {
          title: `${this.$t("equipCheck.Model")}`,
          key: "deviceSpec",
          align: "center",
          minWidth: 150,
          resizable: true,
          tooltip: true,
        },
        {
          title: "功能位置",
          key: "installPositionName",
          align: "center",
          minWidth: 200,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("preliminary.ManufacturingNumber")}`,
          key: "factoryNo",
          align: "center",
          minWidth: 190,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("ledger.PBoxBinding")}`,
          key: "isBindBox",
          align: "center",
          minWidth: 140,
          // slot: "isBindBox",
          resizable: true,
          tooltip: true,
        },
        {
          title: "提报状态",
          key: "enable",
          align: "center",
          minWidth: 140,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("ledger.FixedAssetsTransferDate")}`,
          key: "toRegularDate",
          align: "center",
          minWidth: 200,
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("common.operation")}`,
          slot: "action",
          minWidth: this.util.autoWidth(260, 275),
          align: "center",
          fixed: "right",
        },
      ],
      tagList: [{ id: "", name: this.$t("common.all") }],
      orgList: [],
      fileList: [],
      showFileList: [],
      ids: [],
      deviceList: [
        { label: "A", value: "A" },
        { label: "B", value: "B" },
        { label: "C", value: "C" },
      ],
      boxs: [
        { label: this.$t("common.Yes"), value: "是" },
        { label: this.$t("common.No"), value: "否" },
      ],
      assetsList: [],
      deviceTypeList: [],
      deviceMid: "",
      printArr: [],
      dataSource: [],
      handleContextMenuStatus: true,
      deviceStatusList: [],
    };
  },
  created() {
    this.getTableColumnsWidth(this.columns);
    // this.searchList()
    this.getCompanyList();
    this.getOrgList();
    this.getAssetsClass();
    this.getFaultCategory("deviceStatusList", "设备状态");
    this.getDeviceType();
  },
  activated() {
    this.searchList();
    // this.reset();
  },
  mounted() {
    this.handleContextMenuToggle();
    let itemList = JSON.parse(window.localStorage.getItem("USER_URI"));
    for (let item of itemList) {
      if (item.code == "dmsDeviceTzGetDevicePrint") {
        this.checkBtnPermission.dmsDeviceTzGetDevicePrint = true;
      }
      if (item.code == "dmsDeviceTzTemplate") {
        this.checkBtnPermission.dmsDeviceTzTemplate = true;
      }
      if (item.code == "dmsDeviceTzGetDeviceTzList") {
        this.checkBtnPermission.dmsDeviceTzGetDeviceTzList = true;
      }
      if (item.code == "dmsDeviceTzGetTzDetailByDeviceEq") {
        this.checkBtnPermission.dmsDeviceTzGetTzDetailByDeviceEq = true;
      }
      if (item.code == "dmsDeviceTzImport") {
        this.checkBtnPermission.dmsDeviceTzImport = true;
      }
      if (item.code == "dmsDeviceTzExportTz") {
        this.checkBtnPermission.dmsDeviceTzExportTz = true;
      }
      if (item.code == "dmsDeviceTzUpdateDeviceNo") {
        this.checkBtnPermission.dmsDeviceTzUpdateDeviceNo = true;
      }
      if (item.code == "dmsDeviceTzAddFiles") {
        this.checkBtnPermission.dmsDeviceTzAddFiles = true;
      }
      if (item.code == "dmsDeviceTzGetBatchDevicePrint") {
        this.checkBtnPermission.dmsDeviceTzGetBatchDevicePrint = true;
      }
      if (item.code == "dmsDeviceTzDeleteById") {
        this.checkBtnPermission.dmsDeviceTzDeleteById = true;
      }
      if (item.code == "dmsDeviceTzDeleteByIds") {
        this.checkBtnPermission.dmsDeviceTzDeleteByIds = true;
      }
      if (item.code == "dmsDeviceTzUpdateDevice") {
        this.checkBtnPermission.dmsDeviceTzUpdateDevice = true;
      }
      if (item.code == "dmsDeviceTzImportUpdate") {
        this.checkBtnPermission.dmsDeviceTzImportUpdate = true;
      }
      if (item.code == "dmsDeviceTzScore") {
        this.checkBtnPermission.dmsDeviceTzScore = true;
      }
    }
  },
  beforeRouteLeave(to, from, next) {
    if (to.name == "ledgerDetailModal") {
      from.meta.keepAlive = true;
    } else {
      from.meta.keepAlive = false;
    }
    next();
  },
  methods: {
    changeStatus(state) {
      if (this.ids.length == 0) {
        this.$Message.error("请选择要操作的数据");
      }
      const data = this.ids.map((item) => {
        return {
          id: item,
          enable: state ? "启用" : "禁用",
        };
      });
      this.axios({
        url: "/dms/device/updateEnable",
        method: "post",
        data,
      }).then((res) => {
        if (res.code == 200) {
          this.$Message.success(res.msg);
          this.searchList();
        } else this.$Message.error(res.msg);
      });
    },
    getDeviceType() {
      this.axios({
        method: "get",
        url: "/dms/faultCategory/dictList",
        params: {
          name: "设备类别",
        },
      }).then((res) => {
        if (res.code === 200) {
          this.deviceTypeList = res.data;
        }
      });
    },
    // handleContextMenuToggle () {
    //   this.handleContextMenuStatus = !this.handleContextMenuStatus;
    //
    //   const obj = {
    //     title: `${this.$t('common.operation')}`,
    //     slot: "action",
    //     minWidth: this.util.autoWidth(250, 265),
    //     align: "center",
    //     fixed: 'right',
    //   }
    //
    //
    //
    //   if (this.handleContextMenuStatus){
    //     this.columns = [...this.columnsTemplate]
    //   }else{
    //     this.columns = [...this.columnsTemplate,obj]
    //   }
    //
    //   this.$forceUpdate()
    // },
    getFaultCategory(listName, name) {
      this.axios({
        method: "get",
        url: "/dms/faultCategory/dictList",
        params: { name },
      }).then((res) => {
        this[listName] = res.data;
      });
    },
    getAssetsClass(query) {
      if (query) {
        this.axios({
          method: "get",
          url: "/dms/faultCategory/dictList",
          params: {
            name: "资产分类",
          },
        }).then((res) => {
          if (res.code === 200) {
            this.assetsList = res.data;
          }
        });
      }
    },
    importExcelChange(val) {
      this.importExcelState = false;
      if (val === "success") {
        this.changeNum();
      }
    },
    handleChangeTab(name) {
      console.log(name);
      this.tagName = name;
      this.searchParams = {};
      this.searchList();
    },
    exportTemplate() {
      const filName = "设备台账模板";
      this.axios({
        method: "get",
        url: "/dms/dmsDeviceTz/template",
        responseType: "blob",
        params: {},
      }).then((res) => {
        fileDownload(res, filName + ".xlsx");
      });
    },
    exportUpdateTemplate() {
      const filName = "批量更新模板";
      this.axios({
        method: "get",
        url: "/dms/dmsDeviceTz/massUpdateTemplate",
        responseType: "blob",
        params: {},
      }).then((res) => {
        fileDownload(res, filName + ".xlsx");
      });
    },
    exportTemplateClick() {
      let params = {};
      for (let key in this.searchParams) {
        if (key === "orgId" && this.searchParams["orgId"]) {
          const arr = this.searchParams[key];
          const { length, last = length - 1 } = arr;
          this.$set(params, key, arr[last]);
        } else {
          if (this.searchParams[key]) {
            this.$set(params, key, this.searchParams[key]);
          }
        }
      }
      const filName = "设备台账";
      this.axios({
        method: "post",
        url: "/dms/device/export",
        responseType: "blob",
        data: { ...params, ids: this.ids },
      }).then((res) => {
        fileDownload(res, filName + ".xlsx");
      });
    },
    handleUpdateDeviceNo(row) {
      this.id = row.id;
      this.formItem.deviceNo = row.deviceNo;
      this.orgIdinfo = row.orgId;
      this.writeVisible = true;
    },
    handlePreview(item) {
      if (item.filePath) {
        window.open(this.util.filePathToUrl(item.filePath));
      }
    },
    delFileList(id) {
      this.delelteVisible = true;
      this.delId = id;
    },
    selecthandleUpload(file) {
      this.handleUpload(file, "EQUIPMENT_ENGINEERING_DRAWINGS");
      return false;
    },
    selecthandleUpload1(file) {
      this.handleUpload(file, "EQUIPMENT_FACTORY_ACCESSORIES");
      return false;
    },
    selecthandleUpload2(file) {
      this.handleUpload(file, "E_SOP");
      return false;
    },
    selecthandleUpload3(file) {
      this.handleUpload(file, "DEVICE_PICTURE");
      return false;
    },
    handleUpload(file, fileDocumentEnumPath) {
      this.uploadLoading = true;
      let formData = new FormData();
      formData.append("dir", "device");
      formData.append("file", file);
      let config = {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      };
      this.axios({
        method: "post",
        url: "/fileServer/upload",
        data: formData,
        config,
      })
        .then((res) => {
          if (res.code == 200) {
            let dmsAttachmentList = [];
            const { fileName, filepath, fileUrl, fileLength, suffix } =
              res.data;
            dmsAttachmentList.push({
              businessId: this.uploadId,
              fileName,
              filePath: filepath,
              fileUrl,
              fileDocumentEnumPath,
              fileSize: fileLength,
              suffix,
            });
            this.axios({
              method: "post",
              url: "/dms/dmsDeviceTz/addFiles",
              data: dmsAttachmentList,
            })
              .then((res) => {
                if (res.code == 200) {
                  this.getUploadFile();
                  this.$Message.success("上传成功");
                } else {
                  this.$Message.warning({
                    content: res.msg,
                    duration: 6,
                    closable: true,
                  });
                }
              })
              .finally(() => {
                this.uploadLoading = false;
                // this.uploadVisible = false
              });
          } else {
            this.$Message.warning({
              content: res.msg,
              duration: 6,
              closable: true,
            });
          }
        })
        .catch(() => {
          this.uploadLoading = false;
        });
      return false;
    },
    handleManyFile(row) {
      this.uploadVisible = true;
      this.uploadId = row.id;
      this.deviceMid = row.deviceMId;
      // this.fileList = []
      this.getUploadFile();
    },

    getUploadFile() {
      this.axios({
        method: "get",
        url: "/dms/dmsAttachment/get",
        params: {
          deviceMId: this.deviceMid,
          type: 2,
          // fileDocumentEnum:['EQUIPMENT_ENGINEERING_DRAWINGS','EQUIPMENT_FACTORY_ACCESSORIES','E_SOP']
        },
      })
        .then((res) => {
          if (res.code == 200) {
            this.fileList = res.data;
          } else {
            this.$Message.warning({
              content: res.msg,
              duration: 6,
              closable: true,
            });
          }
        })
        .finally(() => {});
    },
    // handleUploadOk() {
    //     console.log(this.fileList.length)
    //     this.uploadLoading = true
    //     if(this.fileList.length > 0){
    //         this.uploadLoading = true;
    //         let formData = new FormData();
    //         formData.append("dir", 'device')
    //         //多个文件上传
    //         for(let i=0; i< this.fileList.length; i++){
    //             formData.append("file",this.fileList[i]);   // 文件对象
    //         }
    //         let config = {
    //             headers: {
    //                 "Content-Type": "multipart/form-data"
    //             }
    //         };
    //         this.axios({
    //             method: 'post',
    //             url: '/fileServer/uploadMany',
    //             data: formData,
    //             config,
    //         }).then(res => {
    //
    //             if (res.code == 200) {
    //                 let dmsAttachmentList = res.data.map(item => {
    //                     return {
    //                         deviceMId: this.uploadId,
    //                         fileName: item.fileName,
    //                         filePath: item.filepath,
    //                         fileUrl: item.fileUrl
    //                     }
    //                 })
    //                 this.axios({
    //                     method: 'post',
    //                     url: '/dms/dmsDeviceTz/addFiles',
    //                     data: dmsAttachmentList
    //                 }).then(res => {
    //
    //                     if (res.code == 200) {
    //                         this.$Message.success('上传成功')
    //                     }else {
    //                         this.$Message.warning(({content: res.msg, duration: 6, closable: true}))
    //                     }
    //                 }).finally(() => {
    //                     this.uploadLoading = false
    //                     this.uploadVisible = false
    //                 });
    //             }else {
    //                 this.$Message.warning(({content: res.msg, duration: 6, closable: true}))
    //             }
    //         }).catch(() => {
    //             this.uploadLoading = false
    //         });
    //     }else{
    //         this.$Message.warning(({content: "请至少上传一个文件", duration: 6, closable: true}));
    //     }
    // },
    handleDeleteOk() {
      this.delLoading = true;
      this.axios({
        method: "get",
        url: "/dms/dmsAttachment/del",
        params: {
          id: this.delId,
        },
      })
        .then((res) => {
          if (res.code == 200) {
            this.getUploadFile();
            this.$Message.success({
              content: "删除成功！",
              duration: 6,
              closable: true,
            });
          } else {
            this.$Message.warning({
              content: res.msg,
              duration: 6,
              closable: true,
            });
          }
        })
        .finally(() => {
          this.delLoading = false;
          this.delelteVisible = false;
        });
    },
    handleOk() {
      this.$refs.deviceNoForm.validate((valid) => {
        console.log(valid);
        if (valid) {
          this.loading = true;
          this.axios({
            method: "post",
            url: "/dms/dmsDeviceTz/updateDeviceNo",
            data: {
              id: this.id,
              orgId: this.orgIdinfo,
              deviceNo: this.formItem.deviceNo,
            },
          })
            .then((res) => {
              if (res.code === 200) {
                this.$Message.success({
                  content: "修改成功",
                  duration: 3,
                  closable: true,
                });
                this.searchList();
              } else {
                this.$Message.warning({
                  content: res.msg,
                  duration: 6,
                  closable: true,
                });
              }
            })
            .finally(() => {
              this.loading = false;
              this.writeVisible = false;
            });
        }
      });
    },
    //批量导入
    handleBatchImport(status) {
      this.isUpdate = status;
      this.importExcelState = true;
    },
    //批量打印
    handleBatchPrint() {
      this.$refs.ledgerBatchPrintModal.show(this.ids);
    },
    handleChangeVisible() {
      this.$refs.selection.selectAll(false);
    },
    //批量操作
    handleSelectionChange(selectionData) {
      console.log(selectionData);
      let arr = [];
      let arr1 = [];
      selectionData.forEach((item) => {
        arr.push(item.id);
        arr1.push(item);
      });
      this.printArr = arr1;
      this.ids = arr;
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },
    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    searchList() {
      let searchParams = JSON.parse(JSON.stringify(this.searchParams));

      let params = {
        companyId: this.tagName ? this.tagName : "",
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      };
      for (let key in searchParams) {
        if (key === "installPosition" && searchParams["installPosition"]) {
          const arr = searchParams[key];
          const { length, last = length - 1 } = arr;
          if (arr[last]) {
            this.$set(params, key, [arr[last]]);
          }
        } else {
          this.$set(params, key, searchParams[key]);
        }
      }
      if (params.timeOfTurnToFixedAssets) {
        params.timeOfTurnToFixedAssets = moment(
          params.timeOfTurnToFixedAssets
        ).format("YYYY-MM-DD");
      }
      this.axios({
        method: "post",
        url: "/dms/device/page",
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataSource = res.data.records;
          res.data.records.forEach((val) => {
            if (val.categoryName) {
              val.categoryName = val.categoryName;
            }
          });
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    //公司列表
    getCompanyList() {
      this.axios({
        method: "get",
        url: "/basic/company/getCompanyListByUser",
        params: {},
      }).then((res) => {
        if (res.code === 200) {
          let arr = res.data.map((item) => {
            return {
              ...item,
              id: item.id.toString(),
            };
          });
          this.tagList = [...this.tagList, ...arr];
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    getOrgList() {
      let params = {
        level: 0,
      };
      findOrgByToken(params).then((res) => {
        if (res.code === 200) {
          const obj = {
            label: "name",
            value: "code",
            children: "children",
          };
          this.orgList = recursion.convertTree(res.data, obj);
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    //设备类别
    getDeviceList() {
      this.axios({
        method: "get",
        url: "/dms/dmsCategory/getSelectList",
        params: {},
      }).then((res) => {
        if (res.code === 200) {
          // res.data.forEach(val=>{
          //   switch (val['label']) {
          //     case 'MME':
          //       val.label = 'A类'
          //           break;
          //     case 'HME':
          //       val.label = 'B类'
          //       break;
          //     case 'AME':
          //       val.label = 'C类'
          //       break;
          //   }
          // })
          this.deviceList = res.data;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    handleledgerScore({ id }) {
      this.gotoScore([id]);
    },
    gotoScore(ids) {
      this.$router.push({
        path: "/devBasic/equipmentsLedgerManagement/equipmentScore",
        query: { ids },
      });
    },
    //详情页
    handleledgerDetail({ deviceMId, assetsNo, id, deviceName,deviceNo }) {
      if (this.checkBtnPermission.dmsDeviceTzGetTzDetailByDeviceEq) {
        this.$router.push({
          path: "/devBasic/equipmentsLedgerManagement/ledgerDetailModal",
          query: {
            deviceName,
            deviceMId,
            assetsNo,
            id,
            deviceNo,
            status: "detail",
          },
        });
      }
    },
    handlePrint(record) {
      let arr = [];
      arr.push(record);
      this.$refs.ledgerPrintModal.show(arr, 1);
    },
    //批量打印
    printShowClick() {
      if (this.printArr.length == 0) {
        return;
      } else {
        this.$refs.ledgerPrintModal.show(this.printArr, 1);
      }
    },
    //删除
    handleDelete(record) {
      this.status = 0;
      this.delDeviceId = record.id;
      this.delFaultCodeShowF = true;
    },
    batchScore() {
      if (!(this.ids && this.ids.length)) {
        this.$Message.warning({
          content: `${this.$t("common.selectInfo")}`,
          duration: 6,
          closable: true,
        });
        return;
      }
      this.gotoScore(this.ids);
    },
    //批量删除
    handleMulDelete() {
      if (!(this.ids && this.ids.length)) {
        this.$Message.warning({
          content: `${this.$t("common.deleteItems")}`,
          duration: 6,
          closable: true,
        });
        return;
      }
      this.status = 1;
      this.delFaultCodeShowF = true;
    },
    deleteOk() {
      this.delLoading = true;
      if (this.status == 0) {
        this.axios({
          method: "DELETE",
          url: "/dms/device/delete",
          data: [this.delDeviceId],
        })
          .then((res) => {
            if (res.code === 200) {
              this.searchList();
              this.$Message.success({
                content: "删除成功！",
                duration: 2,
                closable: true,
              });
            } else {
              this.$Message.warning({
                content: res.msg,
                duration: 6,
                closable: true,
              });
            }
          })
          .finally(() => {
            this.delLoading = false;
            this.delFaultCodeShowF = false;
          });
      } else {
        this.axios({
          method: "delete",
          url: "/dms/device/delete",
          data: this.ids,
        })
          .then((res) => {
            if (res.code === 200) {
              this.searchList();
              this.$Message.success({
                content: "批量删除成功！",
                duration: 2,
                closable: true,
              });
            } else {
              this.$Message.warning({
                content: res.msg,
                duration: 6,
                closable: true,
              });
            }
          })
          .finally(() => {
            this.delLoading = false;
            this.delFaultCodeShowF = false;
          });
      }
    },
    updateInfo(record) {
      let query = {
        // deviceMId: record.deviceMId,
        // assetsNo: record.assetsNo,
        // id: record.id,
        // status: "update",
      };
      if (record.id) {
        query.id = record.id;
        query.status = "update";
      } else {
        query = {
          status: "add",
        };
      }
      this.$router.push({
        path: "/devBasic/equipmentsLedgerManagement/ledgerDetailModal",
        query,
      });
    },
  },
};
</script>
<style scoped lang="scss">
::v-deep .ivu-upload-drag {
  border: none !important;
}

::v-deep .ivu-dropdown-item {
  padding: 0 !important;

  span.operationBtn {
    padding: 5px 20px;
  }
}

.equipmentDataManagement {
  .ivu-tabs.ivu-tabs-card {
    .ivu-tabs-tab {
      width: 120px !important;
      text-align: center;
    }

    ::v-deep .ivu-tabs-tab.ivu-tabs-tab-active {
      color: #ffffff;
      background-color: #2d8cf0;
    }
  }
}

.uploadFile {
  ::v-deep .ivu-tag-border:after {
    background: #91d5ff;
  }

  ::v-deep .ivu-tag .ivu-icon-ios-close {
    color: #1890ff;
  }
}

.file-list {
  /*margin: 20px;*/
  .item-src {
    display: inline-block;
    line-height: 26px;
    color: #187bdb;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .item-icon {
    width: 20%;
    display: inline-block;
    margin-top: 4px;
  }
}
</style>
